package com.transaction.manager;

import java.util.UUID;

import javax.jws.WebService;
import javax.xml.ws.Holder;

import org.springframework.stereotype.Component;
import org.springframework.transaction.interceptor.CommitPoint;
import org.springframework.transaction.interceptor.TransactionFactory;

/**
 * 对不同服务统一事务处理
 * @author Administrator
 *
 */
@WebService(endpointInterface = "com.transaction.manager.TransactionService")
@Component("transactionService")
public class TransactionServiceImpl implements TransactionService {
	
	public String start(Holder<String> result){
		return start(this.getClass(), "end", result);
	}
	
	private String start(Class<?> cls, String methodName, Holder<String> result){
		String transactionId = createTransactionId();
		
		CommitPoint commitPoint = new CommitPoint();
		commitPoint.setCls(cls);
		commitPoint.setMethodName(methodName);
		commitPoint.setTransactionId(transactionId);
		
		TransactionFactory.init().putCommitPoint(transactionId, commitPoint);
		
		return transactionId;
	}
	public void end(String transactionId){
		
	}
	
	private String createTransactionId() {
		return UUID.randomUUID().toString();
	}
}
